package com.example.gw_back_end.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Sha3Util {
    public static String sha3_256(String input) {
        return sha3(input, "SHA3-256");
    }

    public static String sha3_512(String input) {
        return sha3(input, "SHA3-512");
    }

    private static String sha3(String input, String algorithm) {
        try {
            MessageDigest digest = MessageDigest.getInstance(algorithm);
            byte[] hash = digest.digest(input.getBytes());
            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Hash algorithm not found: " + e.getMessage(), e);
        }
    }
}
